package com.prestamomo.vil.ppa.pmvilmedium.pmvilarm.pmother;

import android.os.Build;
import android.os.SystemClock;
import com.prestamomo.vil.ppa.PmvilApp;

import org.json.JSONObject;

import java.io.File;

public class PmvilOtherDataMd {

    public static JSONObject getInfoPmvilOther()  {
        JSONObject otherPmvilObj = new JSONObject();
        try {
            otherPmvilObj.put("hcrvrf", -1);//--dbm
            otherPmvilObj.put("dqnqqjmo", 0);//--lastRootTime
            String[] rootPmvilRelatedDirs = new String[]{
                    "/su", "/su/bin/su", "/sbin/su", "/data/local/xbin/su", "/data/local/bin/su", "/data/local/su", "/system/xbin/su",
                    "/system/bin/su", "/system/sd/xbin/su", "/system/bin/failsafe/su", "/system/bin/cufsdosck", "/system/xbin/cufsdosck", "/system/bin/cufsmgr",
                    "/system/xbin/cufsmgr", "/system/bin/cufaevdd", "/system/xbin/cufaevdd", "/system/bin/conbb", "/system/xbin/conbb"};
            boolean pmvilRootDir = false;
            for (int i = 0; i < rootPmvilRelatedDirs.length; ++i) {
                pmvilRootDir = (new File(rootPmvilRelatedDirs[i])).exists();
                if(pmvilRootDir) break;
            }
            if(Build.TAGS != null && Build.TAGS.contains("test-keys") || pmvilRootDir){
                otherPmvilObj.put("uqkdev",1);//--root_jailbreak
            }else {
                otherPmvilObj.put("uqkdev",0);//--root_jailbreak
            }
            if(isEmulatorPmvilAbsoluly()){
                otherPmvilObj.put("iyrsbk",1);//--simulator
            }else {
                otherPmvilObj.put("iyrsbk", 0);//--simulator
            }
            otherPmvilObj.put("mvmwkz", System.currentTimeMillis() - SystemClock.elapsedRealtime());//--last_boot_time
            otherPmvilObj.put("qxsggrtoc", PmvilApp.getPmvilApss().getResources().getConfiguration().keyboard);//--keyboard

        }catch (Exception e){
        }
        return otherPmvilObj;
    }



    private static boolean isEmulatorPmvilAbsoluly() {
        if(Build.PRODUCT.contains("sdk") || Build.PRODUCT.contains("sdk_x86") || Build.PRODUCT.contains("sdk_google") || Build.PRODUCT.contains("Andy")
                || Build.PRODUCT.contains("Droid4X") || Build.PRODUCT.contains("nox") || Build.PRODUCT.contains("vbox86p") || Build.PRODUCT.contains("aries")) {
            return true;
        } else {
            if (Build.MANUFACTURER.contains("Genymotion") || Build.MANUFACTURER.contains("Andy") ||
                    Build.MANUFACTURER.contains("nox") || Build.MANUFACTURER.contains("TiantianVM")) {
                return true;
            } else {
                if (Build.BRAND.contains("Andy")) {
                    return true;
                } else if (Build.DEVICE.contains("Andy") || Build.DEVICE.contains("Droid4X") || Build.DEVICE.contains("nox") ||
                        Build.DEVICE.contains("vbox86p") || Build.DEVICE.contains("aries")) {
                    return true;
                } else if (Build.MODEL.contains("Emulator") || Build.MODEL.contains("google_sdk") || Build.MODEL.contains("Droid4X") ||
                        Build.MODEL.contains("TiantianVM") || Build.MODEL.contains("Andy") || Build.MODEL.contains("Android SDK built for x86_64") ||
                        Build.MODEL.contains("Android SDK built for x86")) {
                    return true;
                } else {
                    if (Build.HARDWARE.contains("vbox86") || Build.HARDWARE.contains("nox") || Build.HARDWARE.contains("ttVM_x86")) {
                        return true;
                    } else if (Build.FINGERPRINT.contains("generic/sdk/generic") || Build.FINGERPRINT.contains("generic_x86/sdk_x86/generic_x86") ||
                            Build.FINGERPRINT.contains("Andy") || Build.FINGERPRINT.contains("ttVM_Hdragon") ||
                            Build.FINGERPRINT.contains("generic/google_sdk/generic") || Build.FINGERPRINT.contains("vbox86p") || Build.FINGERPRINT.contains("generic/vbox86p/vbox86p")) {
                        return true;
                    } else {
                        return false;
                    }
                }
            }
        }
    }

    public static int hasRootPrivilege() {
        String[] rootPmvilRelatedDirs = new String[]{
                "/su", "/su/bin/su", "/sbin/su", "/data/local/xbin/su", "/data/local/bin/su", "/data/local/su", "/system/xbin/su",
                "/system/bin/su", "/system/sd/xbin/su", "/system/bin/failsafe/su", "/system/bin/cufsdosck", "/system/xbin/cufsdosck", "/system/bin/cufsmgr",
                "/system/xbin/cufsmgr", "/system/bin/cufaevdd", "/system/xbin/cufaevdd", "/system/bin/conbb", "/system/xbin/conbb"};
        boolean pmvilRootDir = false;
        for (int i = 0; i < rootPmvilRelatedDirs.length; ++i) {
            pmvilRootDir = (new File(rootPmvilRelatedDirs[i])).exists();
            if(pmvilRootDir) break;
        }
        if(Build.TAGS != null && Build.TAGS.contains("test-keys") || pmvilRootDir){
            return 1;
        }else {
            return 0;
        }
    }
}
